Skip to content

[JAY-749] Add a method to retrieve the list of tasks running on the Elasticsearch cluster#62

Merged
sergio-bobillier merged 5 commits intomasterfrom
sb-JAY-749-monitor-tasks
Mar 13, 2026
Merged

[JAY-749] Add a method to retrieve the list of tasks running on the Elasticsearch cluster#62
sergio-bobillier merged 5 commits intomasterfrom
sb-JAY-749-monitor-tasks

Conversation

@sergio-bobillier
Copy link
Collaborator

The main objective in this pull request is to add the #all method to the Elasticsearch::Tasks class. The method returns a Hash with the list of tasks currently running on the Elasticsearch cluster.

The main use case for this method at the time of writing was to monitor the Segment Merge tasks since requests for such tasks pretty much always timeout due to long execution times.

To avoid code duplication and further coupling of the Tasks and the Client classes the following changes are also being made:

  • A new #tasks method is being added to the Client class. This method returns an instance of the Tasks class that is initialized with the Client instance. This releaves the caller from having to initialize the Tasks class directly and allows for better encapsulation of the Client class.
  • All the code related to request retries is being moved out of the Client class and into a new RetriableRequest mixin. The mixin is then being used by both the Client and the Tasks classes.
  • The code in the Tasks#by_id method is being refactored to avoid using the #task_by_id method in the Client class, which is beign deprecated and will be removed in a future commit.

The method allows the caller to retrieve information about the currently
running tasks in the cluster.

The underlying logic (the Elasticsearch::Tasks class) already existed,
this change only makes it accessible through the client, instead of
forcing the caller to initialize the class directly (which requires the
client to be passed to it).
Moves the logic to retry Elasticsearch requests out of the Client class
and into a new mixin module. This allows other classes to reuse the
retry logic.

The mixin will be used in an upcoming commit to decouple the Tasks class
from the Client class and to add some new methods to it.
Changes the Tasks class' #by_id method to stop using the #task_by_id
method of the Client class.

This decouples the classes because it allows the Tasks class'
dependencies to be injected. It no longer requires the Client class to
define a method specifically for the Tasks class. And allows the Tasks
class to be used with any client that can provide it with access to
Elasticsearch's transport client.

To make sure that the class has retained its functionality a very basic
integration test is being added.
This method causes a coupling between Tasks and Client, which is not
ideal. Hence it is being deprecated and will be removed in an upcomming
commit.
The method returns a Hash with information about the tasks running on
the Elasticsearch cluster.

The method accepts an optional argument to filter the tasks by their
action type and a boolean argument that causes Elasticsearch to add
detailed information about each task to the response when set to true.
@sergio-bobillier sergio-bobillier force-pushed the sb-JAY-749-monitor-tasks branch from 0857853 to 4618796 Compare March 10, 2026 09:39
@sergio-bobillier sergio-bobillier merged commit 0b03a6e into master Mar 13, 2026
2 checks passed
@sergio-bobillier sergio-bobillier deleted the sb-JAY-749-monitor-tasks branch March 13, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants